package cn.ly.checkin.service.test;

import static org.junit.Assert.*;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

import cn.ly.checkin.domain.User;
import cn.ly.checkin.service.UserService;

public class MainTest2 {
	
//	@Test
	public void userService(){
		ApplicationContext act=new FileSystemXmlApplicationContext("e:/config/UserServiceTests-context.xml");
		UserService userService=(UserService) act.getBean("userService");
		assertNotNull(userService);
		
	}
	public static void main(String [] args) throws IOException{
		MainTest2 test=new MainTest2();
//		test.userService();
		test.context();
//		test.loader();
//		test.resource();
	}
	@Test
	public void stringTest(){
		String str="%3F%3F%3F%3F%3F%3F%3F%3F%3F";
		try {
			String ecd=URLDecoder.decode(str,"utf-8");
			System.out.println(ecd);
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		byte[] bs;
		try {
			bs = str.getBytes("utf-8");
			String utf8=new String(bs);
			System.out.println(utf8);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public void loader(){
//		ClassLoader sysLoader=ClassLoader.getSystemClassLoader();
		ClassLoader currntLoader=this.getClass().getClassLoader();
		URL urls[]=((URLClassLoader)currntLoader).getURLs();
		for(URL url:urls){
			System.out.println(url.getFile());
		}
		if(false){
			try {
				throw new IOException("null");
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	public static void resource() throws IOException{
		String filePath="e:/config/UserServiceTests-context.xml";
		Resource res1=new FileSystemResource(filePath);
		InputStream ins=res1.getInputStream();
		System.out.println(res1.getDescription());
	}
//	@Test
	public void context(){
		ApplicationContext act=new ClassPathXmlApplicationContext("classpath:context.xml");
		UserService userService=(UserService) act.getBean("userService");
		User user=userService.findByNameAndPssword("lee", "yon");
		
	}

}
